package com.dd.shop4j.console.system.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dd.shop4j.common.utils.Constant;
import com.dd.shop4j.console.system.service.SystemManagerService;
import com.dd.shop4j.sys.model.SysConstant;
import com.dd.shop4j.sys.service.SysConstantService;

@Controller
@RequestMapping("/admin/sysconst")
public class SystemConstantController {
	
	@Resource private SystemManagerService systemManagerService;
	@Resource private SysConstantService sysConstantService;
	
	@RequestMapping("/list")
	public ModelAndView constants(SysConstant constant, Integer curpage, Integer pagesize) {
		if (curpage == null || curpage <= 0) {
			curpage = 1;
		}
		if (pagesize == null || pagesize <= 0) {
			pagesize = sysConstantService.getInteger(Constant.PAGE_SIZE_CODE);
		}
		ModelAndView view = new ModelAndView("/admin/system/constant_list");
		view.addObject("constant", constant);
		view.addObject("page", systemManagerService.queryConstantByPage(constant, curpage, pagesize));
		return view;
	}
	
	@ResponseBody
	@RequestMapping("/update")
	public boolean update(SysConstant constant) {
		return systemManagerService.updateConstant(constant) > 0;
	}

}
